'''
https://www.nowcoder.com/practice/7c4559f138e74ceb9ba57d76fd169967
'''

import sys

class Map:
    def __init__(self):
        self.map = {}
        self.t = 0
        self.set_all_t = 0      # time t
        self.set_all_v = -1

    def put(self, key, value):
        self.map[key] = (value, self.t)
        self.t += 1

    def get(self, key):
        if key not in self.map:
            return '-1'
        v, t = self.map[key]
        if t < self.set_all_t:
            return self.set_all_v
        return v

    def set_all(self, value):
        self.set_all_t = self.t
        self.set_all_v = value
        self.t += 1

dic = Map()
n = int(sys.stdin.readline().strip())
for i in range(n):
    a = sys.stdin.readline().strip().split()
    opt = a[0]
    if opt == '1':
        # put
        dic.put(a[1], a[2])
    elif opt == '2':
        # get
        v = dic.get(a[1])
        sys.stdout.write(v + '\n')
    else:
        # set_all
        dic.set_all(a[1])